<template>
    <!-- 弹出学生详细信息对话框 -->
    <el-dialog title="会议记录详细信息" :visible.sync="scanMinutesFormVisible">
    <el-form :model="browseDetailData">
        <el-form-item  label="会议记录ID" :label-width="formLabelWidth">
        <el-input v-model="browseDetailData.minutesId" autocomplete="off" :readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="会议记录时间" :label-width="formLabelWidth">
        <el-input v-model="browseDetailData.minutesTime" autocomplete="off" :readonly="readonly"></el-input>
        </el-form-item>
      <el-form-item label="标题" :label-width="formLabelWidth">
        <el-input v-model="browseDetailData.minutesTitle" autocomplete="off" :readonly="readonly"></el-input>
      </el-form-item>
      <el-form-item label="会议内容" :label-width="formLabelWidth">
        <el-input type="textarea" v-model="browseDetailData.minutesContent" autocomplete="off" :readonly="readonly"></el-input>
        </el-form-item>
      <el-form-item label="照片" :label-width="formLabelWidth">
        <el-col :span="12">
          <div class="demo-basic--circle" style="float:left">
            <!-- :src="require('@/assets/upload/' + browseDetailData.stuPhoto)" -->
            <div class="block">
              <el-avatar shape="square" :size="150" :src="require('@/assets/upload/' + browseDetailData.minutesImg)"  >
              </el-avatar></div>
          </div>
        </el-col>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <div v-if="readonly==false" >
        <el-button type="primary" @click="updateMinutes">更 新</el-button>
      </div>
        <el-button type="primary" @click="scanMinutesFormVisible = false">关 闭</el-button>
    </div>
    </el-dialog>
</template>

<script>
    // 引入公共的bug，来做为中间传达的工具
    import Bus from '@/components/Bus/bus.js'
    // 引入qs实现字符串转换为可以提交的类型
    import * as qs from "qs";

    export default {
        data() {
            return {
                // 详细信息展示的数据
                browseDetailData: {
                  minutesId: '',
                  minutesTime: '',
                  minutesUploadUser: '',
                  minutesImg: '',
                  minutesContent: '',
                  minutesTitle: '',
                },
                // 设置弹出信息宽度
                formLabelWidth: '100px',
                // 弹出添加学生记录对话框
                scanMinutesFormVisible: false,
                // 是否为只读（不可编辑） 如果管理员等级小于2那么设置为只读（不可编辑）
                readonly: this.$store.state.role<2?true:false,
            }
        },
        mounted: function () {
            // 用$on事件来接收参数 判断查看/编辑详细信息页面是否显示
            Bus.$on('scanMinutesFormVisible', (data) => {
                this.scanMinutesFormVisible = data;
            })
            // 用$on事件来接收参数  获取用户点击的stuId
            Bus.$on('minutesId', (data) => {
                // 通过then方法获取promise对象
                this.$axios({
                    method: "get",
                    url: "admin/getMinutesByMinutesId/"+data,
                }).then((response) => {
                    if (response.data['data'] != null) {
                        console.log(response.data['data']);
                        // res为获得到的state里的数据
                        // 包含 照片，姓名，性别，籍贯，联系方式，状态，家庭住址，班主任
                        this.browseDetailData.minutesId = data ;
                        this.browseDetailData.minutesTime = response.data['data'].minutesTime;
                        this.browseDetailData.minutesUploadUser = response.data['data'].minutesUploadUser ;
                        this.browseDetailData.minutesImg = response.data['data'].minutesImg ;
                        this.browseDetailData.minutesContent = response.data['data'].minutesContent ;
                        this.browseDetailData.minutesTitle = response.data['data'].minutesTitle ;
                    }
                })
            })
        },
        methods: {
            // Get方法 返回一个Promise对象
            getRequest : async function(url) {
                let getAwait = ()=>{
                    return new Promise(resolve => {
                        this.$axios({
                            method: "get",
                            url: url,
                        }).then((response) => {
                        if (response.data['data'] != null) {
                            resolve(response.data['data']);
                        }
                    })
                });
                }
                let result = await getAwait();
                //console.log(result); 
                return result;
            },
            // 更新会议内容
            updateMinutes(){
              console.log("更新会议内容");
              // POST方式提交表单信息，学生登录成功后跳转到StudentInfo.vue界面
              this.$axios({
                method: "post",
                url: "admin/updateMinutes",
                data: qs.stringify({data:JSON.stringify(this.browseDetailData)}),
              }).then((res) => {
                console.log(res.data);
                if(res.data.code == "200"){
                  alert("更新成功");
                }else if(res.data.code == "400"){
                  alert("参数错误");
                }else if(res.data.code == "500"){
                  alert("网络异常");
                }
              }).catch(err => {
                console.log(err.response);
              })
            }
        }
    }
</script>
